// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   Wall.java

package jones;

import java.awt.geom.*;
import java.io.PrintStream;
import jones.rigid.ConvexPolygon;
import jones.rigid.SimpleRigidBody;

public class Wall extends SimpleRigidBody
{

    private double x1 = 0;
    private double y1 = 0;
    private double x2 = 0;
    private double y2 = 0;
    private double width = 0;

    public Wall(double x1, double y1, double x2, double y2, double width)
    {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.width = width;
        init();
    }

    public Wall(Wall wall)
    {
        super(((SimpleRigidBody) (wall)));
        x1 = wall.x1;
        y1 = wall.y1;
        x2 = wall.x2;
        y2 = wall.y2;
        width = wall.width;
    }

    private void init()
    {
        setPushable(false);
        double distance = Point2D.distance(x1, y1, x2, y2);
        double angle = Math.atan2(y2 - y1, x2 - x1);
        double dx = (width / 2D) * Math.cos(1.5707963267948966D - angle);
        double dy = (width / 2D) * Math.sin(1.5707963267948966D - angle);
        int n = 4;
        double x[] = new double[n];
        double y[] = new double[n];
        x[0] = x1 + dx;
        y[0] = y1 - dy;
        x[1] = x2 + dx;
        y[1] = y2 - dy;
        x[2] = x2 - dx;
        y[2] = y2 + dy;
        x[3] = x1 - dx;
        y[3] = y1 + dy;
        ConvexPolygon shape = new ConvexPolygon(x, y, n);
        try
        {
            shape.transform(getTransform(((AffineTransform) (null))).createInverse());
            setShape(shape);
        }
        catch (NoninvertibleTransformException ex)
        {
            System.err.println("transform=" + shape.toString());
            ex.printStackTrace();
        }
    }

    public void setStartPoint(double x1, double y1)
    {
        this.x1 = x1;
        this.y1 = y1;
        init();
    }

    public double getStartPointX()
    {
        return x1;
    }

    public double getStartPointY()
    {
        return y1;
    }

    public void setEndPoint(double x2, double y2)
    {
        this.x2 = x2;
        this.y2 = y2;
        init();
    }

    public double getEndPointX()
    {
        return x2;
    }

    public double getEndPointY()
    {
        return y2;
    }

    public void setWidth(double width)
    {
        this.width = width;
        init();
    }

    public void setLocation(double x, double y)
    {
        double oldX = getLocationX();
        double oldY = getLocationY();
        super.setLocation(x, y);
        x1 += x - oldX;
        x2 += x - oldX;
        y1 += y - oldY;
        y2 += y - oldY;
        setChanged();
    }
}
